<?php
include("../conf/config.php");
include("../conf/database.php");

//note: if word file for dump desired, link to this page like:
//<a href='dump.php?w=1'>link</a>
//if this parameter is not included, file returned will be in excel format
$w=3;
if ($w==1){
$file_type = "msword";
$file_ending = "doc";
}
else {
$file_type = "vnd.ms-excel";
$file_ending = "xls";
}
header("Content-Type: application/$file_type");
header("Content-Disposition: attachment; filename=IT_Mem_Register.$file_ending");
header("Pragma: no-cache");
header("Expires: 0");
//get contents
//define date for title
$now_date = date('d-m-Y H:i');
$title = "<b>Member Registrations as of $now_date</b>";
$sql = "select * from bkitc_profiles where rec_status=1 order by full_name";

/*    Database Connection (Alternative- for mysql_fetch_array)    */
//Require("connect_defs.php");

$result = @mysql_query($sql)
	or die(mysql_error());
//end of connection code

//define separator (defines columns in excel)
$sep = "\t";

//print excel header with timestamp:
echo("$title\n");

//start of printing column names
for ($i = 0; $i < mysql_num_fields($result); $i++) {
echo mysql_field_name($result,$i) . "\t";
}
print("\n");
//end of printing column names


    $i = 0;
    while($row = mysql_fetch_row($result))
    {
        //set_time_limit(60); // HaRa
        $schema_insert = "";
        for($j=0; $j<mysql_num_fields($result);$j++)
        {
            if(!isset($row[$j]))
                $schema_insert .= "NULL".$sep;
            elseif ($row[$j] != "")
                $schema_insert .= "$row[$j]".$sep;
            else
                $schema_insert .= "".$sep;
        }
        $schema_insert = str_replace($sep."$", "", $schema_insert);
		$schema_insert .= "\t";
        print(trim($schema_insert));
		print "\n";
        $i++;
    }
    return (true);
?>
